package com.dz.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo07 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException, InvocationTargetException, NoSuchMethodException {
        Class cls = Class.forName("com.dz.reflect.Person");
        Object o = cls.newInstance();// 反射创建对象
        Method setName = cls.getDeclaredMethod("setName", String.class);// 反射出单个方法
//        Method setName = cls.getDeclaredMethod("setTime", String.class, int.class);// 反射出单个方法
        setName.invoke(o, "老王");

        Method getName = cls.getDeclaredMethod("getName");
        Object value = getName.invoke(o);
        System.out.println(value);


        // 对于方法来说
    }

}
